package com.gl.ruanzhu.service.impl;

import com.gl.ruanzhu.mapper.InspectionAndTestingMapper;
import com.gl.ruanzhu.model.ApplicationInfo;
import com.gl.ruanzhu.service.IInspectionAndTestingServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Transactional(readOnly = false)
@Service
public class InspectionAndTestingServerImpl implements IInspectionAndTestingServer {

    @Autowired
    InspectionAndTestingMapper inspectionAndTestingMapper;


    @Override
    public List<Map> getInspectionlist(String detectionField, String industryCategory ,int sortType,String instruArea,int currPage, int pageSize) {
        //查所有
      List<Map> mapList=  inspectionAndTestingMapper.getInspectionlist(detectionField,industryCategory,sortType,instruArea);
        //总条数
      int total=inspectionAndTestingMapper.getCounttotal(detectionField,industryCategory,instruArea);
        //从第几条数据开始
        int firstIndex = (currPage - 1) * pageSize;
        //到第几条数据结束
        int lastIndex = currPage * pageSize;
        List<Map>  returnList=new ArrayList<>();
        if (lastIndex>=total){
            returnList =mapList.subList(firstIndex, total);
        }else {
            returnList =mapList.subList(firstIndex, lastIndex);
        }



        return returnList;
    }

    @Override
    public Map getProjectetailsDByid( Map map) {
        Map projectetailsDByid = inspectionAndTestingMapper.getProjectetailsDByid(map);
      //  System.out.println(projectetailsDByid);
        return projectetailsDByid;
    }

    @Override
    public int getCountotal(String detectionField, String industryCategory, String instruArea) {
        //总条数
        int total=inspectionAndTestingMapper.getCounttotal(detectionField,industryCategory,instruArea);
        return total;
    }

    @Override
    public void addApplication(ApplicationInfo applicationInfo) {
        inspectionAndTestingMapper.addApplication(applicationInfo);
    }

    @Override
    public  List<Map> getRecommendProject( ) {
        return inspectionAndTestingMapper.getRecommendProject();
    }

}
